/**
 * 修改状态
 */

import * as type from './type'

const mutations = {
    // 赋值 商品信息
    [type.MODIFY_PRODUCT_INFO](state, actions) {
        state.productInfo = actions.payload
        
        state.goods = {
            title: actions.payload.Name,
            picture: 'http://insidexkd.oss-cn-shanghai.aliyuncs.com/' + actions.payload.Picture[0].imageUrl
        }
        
        state.sku.price = actions.payload.SalePrice
        state.sku.stock_num = actions.payload.StockNum

        state.sku.none_sku = true

        if (!actions.payload.SkuStock) {
            return
        }
        state.sku.none_sku = false
        state.sku.tree = [{
            k: actions.payload.Sku_Name_1.Text,
            v: actions.payload.Sku_Name_1_Value,
            k_s: 's1'
        }, {
            k: actions.payload.Sku_Name_2.Text,
            v: actions.payload.Sku_Name_2_Value,
            k_s: 's2'
        }]
        state.sku.tree.some(item => {
            item.v.some(it => {
                it.id = it.Id,
                it.name = it.Value,
                it.imgUrl = it.ImgPath
            })
        })

        state.sku.list = actions.payload.SkuStock
        state.sku.list.some(item => {
            item.id = item.SkuId
            item.price = item.SalePrice
            item.s1 = item.V1_Id
            item.s2 = item.V2_Id
            item.stock_num = item.StockNum
        })
    }
}

export default mutations